def cut_txt():
    # 计数器
    flag = 0
    # 文件名
    name = 1
    # 存放数据
    dataList = []
    with open('data.txt', 'r', encoding='utf-8') as fp_source:
        for line in fp_source:
            flag += 1
            dataList.append(line)
            # 设置每份文件句子数量
            if flag == 10000:
                with open('data' + str(name) + ".txt", 'w+', encoding='utf-8') as fp_target:
                    for data in dataList:
                        fp_target.write(data)
                name += 1
                flag = 0
                dataList = []

    # 处理最后一批行数少于1万行的
    with open('data' + str(name) + ".txt", 'w+', encoding='utf-8') as fp_target:
        for data in dataList:
            fp_target.write(data)
    print('txt分割完成')

if __name__ == '__main__':
    cut_txt()